#include "resource.h"
#include "loader.h"

using namespace kraw;

Resource::Resource(AssetLoader* _loader) :
loader(_loader),
refCount(0),
memorySize(0)
{
}

Resource::~Resource()
{
}

std::string Resource::getName()
{
	return loader->getAssetName();
}

/**
	Subclasses: implement initialization from loaded
*/
bool Resource::load()
{
	if (loader->loaded()) {
		isLoaded = doLoad();
		return isLoaded;
	}

	return false;
}

void Resource::unload()
{
}

bool Resource::doLoad()
{
	return true;
}

void Resource::doUnload()
{
}

bool Resource::loaded()
{
	return isLoaded;
}

void Resource::retain()
{
	refCount++;
}

void Resource::release()
{
	if (isLoaded) {
		//decrease reference count
		refCount--;
		//if no more references, remove from resource map
		if (refCount <= 0)
			;//report to resource manager
	}
}
